options(scipen=999)

#Set working directory
setwd("insert location of your working directory")

#load required packages
library("xlsx")
library("Hmisc")
library("ggplot2")
library ("car")
library("MASS")
library("psych")
library("GGally")
library("stargazer")
library("DAMisc")

#load datafile
mydata <- read.xlsx("masterdataset_upload_v2.xlsx", 1, stringsAsFactors=FALSE)

#data preparation. convert variables from string to numeric variables. 
mydata$support_Paris_agreement <- as.numeric(mydata$support_Paris_agreement)
mydata$GDP_ppp_2015_log <-as.numeric(mydata$GDP_ppp_2015_log)
mydata$Democracy_index <-as.numeric(mydata$Democracy_index)
mydata$postmaterialism <-as.numeric (mydata$postmaterialism)
mydata$religion <-as.numeric (mydata$religion)
mydata$cosmopolitanism <-as.numeric (mydata$cosmopolitanism)
mydata$political_orientation <-as.numeric (mydata$political_orientation)
mydata$coal_rents_2015 <- as.numeric (mydata$coal_rents_2015)
mydata$oil_rents_2015 <- as.numeric (mydata$oil_rents_2015)
mydata$natural_gas_rents_2015 <- as.numeric (mydata$natural_gas_rents_2015)
mydata$vulnerability_2015 <- as.numeric (mydata$vulnerability_2015)
mydata$Du_Pont_Ambition<-as.numeric(mydata$Du_Pont_Ambition)
mydata$cosmopolitanism_index <- as.numeric (mydata$cosmopolitanism_index)
mydata$CAT_ranking <- as.numeric (mydata$CAT_ranking)
mydata$CCPI_2019 <- as.numeric(mydata$CCPI_2019)

#The dependent variable of this analysis is "Du_Pont_Ambition". We invert the Du Pont ambition variable to facilitate intuitive interpretation. 
mydata$Du_Pont_Ambition <- abs(mydata$Du_Pont_Ambition - max(mydata$Du_Pont_Ambition, na.rm = TRUE))

#descriptive statistics for all variables in dataset. Produces table S3. 
stargazer(mydata,type="text", no.space= TRUE, out="descriptives22.html")


#Bivariate relationships. Produce figures 1-4. 

#bivariate relationship between Paris Agrement Support and NDC Ambition 
theme_set(theme_light())
g <- ggplot(mydata, aes(support_Paris_agreement, Du_Pont_Ambition))
g <- g+ geom_point() + geom_smooth(method="lm", colour="gray", se=F) + labs(y="NDC ambition", x="Paris Agreement support") 
labels_dv_dist <- element_text(face = "plain", size = 12)
g <- g + theme(axis.text = labels_dv_dist)
ggsave(filename = "NDC_amb_PA_support.pdf", plot = g,  path = NULL, scale = 1, limitsize = TRUE, width = 5, height = 5, units = "in", dpi = 300)

#correlation
rcorr(mydata$Du_Pont_Ambition, mydata$support_Paris_agreement, type="pearson")

#Bivariate relationship between NDC Ambition and GDP/capita
theme_set(theme_light())
b <- ggplot(mydata, aes(GDP_ppp_2015_log, Du_Pont_Ambition))
b <- b+ geom_point() + geom_smooth(method="lm", colour="gray", se=F) + labs(y="NDC ambition", x="GDP/Capita(log)") 
labels_dv_dist <- element_text(face = "plain", size = 12)
b <- b + theme(axis.text = labels_dv_dist)
ggsave(filename = "NDC_amb_Gdp.pdf", plot = b,  path = NULL, scale = 1, limitsize = TRUE, width = 5, height = 5, units = "in", dpi = 300)

#correlation
rcorr(mydata$Du_Pont_Ambition, mydata$GDP_ppp_2015_log)

#Bivariate relationship between NDC Ambition and Coal rents
theme_set(theme_light())
c <- ggplot(mydata, aes(coal_rents_2015, Du_Pont_Ambition))
c <- c+ geom_point() + geom_smooth(method="lm", colour="gray", se=F) + labs(y="NDC ambition", x="Coal rents") 
labels_dv_dist <- element_text(face = "plain", size = 12)
c <- c + theme(axis.text = labels_dv_dist)
ggsave(filename = "NDC_amb_coal.pdf", plot = b,  path = NULL, scale = 1, limitsize = TRUE, width = 5, height = 5, units = "in", dpi = 300)

#correlation
rcorr(mydata$Du_Pont_Ambition, mydata$coal_rents_2015)

#Bivariate relationship between NDC Ambition and Democracy
theme_set(theme_light())
d <- ggplot(mydata, aes(Democracy_index, Du_Pont_Ambition))
d <- d+ geom_point() + geom_smooth(method="lm", colour="gray", se=F) + labs(y="NDC ambition", x="Democracy") 
labels_dv_dist <- element_text(face = "plain", size = 12)
d <- d + theme(axis.text = labels_dv_dist)
ggsave(filename = "NDC_amb_democracy.pdf", plot = b,  path = NULL, scale = 1, limitsize = TRUE, width = 5, height = 5, units = "in", dpi = 300)

#correlation
rcorr(mydata$Du_Pont_Ambition, mydata$vulnerability_2015)

#Bivariate relationship NDC Ambition and Postmaterialism
theme_set(theme_light())
f <- ggplot(mydata, aes(postmaterialism, Du_Pont_Ambition))
f <- f+ geom_point() + geom_smooth(method="lm", colour="gray", se=F) + labs(y="NDC ambition", x="Postmaterialism") 
labels_dv_dist <- element_text(face = "plain", size = 12)
f <- f + theme(axis.text = labels_dv_dist)
ggsave(filename = "postmaterialism-ambition.pdf", plot = g,  path = NULL, scale = 1, limitsize = TRUE, width = 5, height = 5, units = "in", dpi = 300)

#correlation
rcorr(mydata$Du_Pont_Ambition, mydata$postmaterialism)


#Bivariate relationship NDC Ambition and Cosmopolitanism
theme_set(theme_light())
h <- ggplot(mydata, aes(cosmopolitanism, Du_Pont_Ambition))
h <- h+ geom_point() + geom_smooth(method="lm", colour="gray", se=F) + labs(y="NDC ambition", x="Cosmopolitanism") 
labels_dv_dist <- element_text(face = "plain", size = 12)
h <- h + theme(axis.text = labels_dv_dist)
ggsave(filename = "cosmopolitanism-ambition.pdf", plot = g,  path = NULL, scale = 1, limitsize = TRUE, width = 5, height = 5, units = "in", dpi = 300)

#correlation
rcorr(mydata$Du_Pont_Ambition, mydata$cosmopolitanism)


#Bivariate relationship NDC Ambition and Vulnerability
theme_set(theme_light())
i <- ggplot(mydata, aes(vulnerability_2015, Du_Pont_Ambition))
i <- i+ geom_point() + geom_smooth(method="lm", colour="gray", se=F) + labs(y="NDC ambition", x="Vulnerability") 
labels_dv_dist <- element_text(face = "plain", size = 12)
i <- i + theme(axis.text = labels_dv_dist)
ggsave(filename = "vulnerability-ambition.pdf", plot = g,  path = NULL, scale = 1, limitsize = TRUE, width = 5, height = 5, units = "in", dpi = 300)
rcorr(mydata$Du_Pont_Ambition, mydata$vulnerability_2015)


#Regression analysis

#The first regression model includes only the material factors. This line of code produces the results in table 1. The stargazer command produces the table.
reg1 <- lm(Du_Pont_Ambition~ GDP_ppp_2015_log+ Democracy_index +coal_rents_2015+natural_gas_rents_2015+oil_rents_2015+vulnerability_2015, data = mydata)
summary(reg1)
stargazer(reg1, type="html", align=TRUE, no.space=TRUE, omit.stat="ser", intercept.bottom = FALSE, single.row = TRUE, out="Material-factors.html")

#The second regression model includes Paris Agreement support and material factors. This line of code produces the results in table 2. The stargazer command produces the table.
reg3 <- Du_Pont_Ambition <- lm (Du_Pont_Ambition~support_Paris_agreement+ GDP_ppp_2015_log+ Democracy_index +coal_rents_2015+ oil_rents_2015 + natural_gas_rents_2015 + vulnerability_2015, data = mydata)
summary(reg3)
stargazer(reg3, type="html", align=TRUE, no.space=TRUE, omit.stat="ser", intercept.bottom = FALSE, single.row = TRUE, out="PA-support.html")

#The third and fourth regression model includes values, with and without material factors. These lines of code produce the results in table 3. The stargazer command produces the table. 
reg2a <- lm (Du_Pont_Ambition~ postmaterialism+cosmopolitanism, data = mydata)
summary(reg2a)
reg2 <- lm (Du_Pont_Ambition~ postmaterialism+cosmopolitanism+ GDP_ppp_2015_log+ v2x_polyarchy_2015 +coal_rents_2015+natural_gas_rents_2015+oil_rents_2015+ vulnerability_2015, data = mydata)
summary(reg2)
stargazer(reg2a,reg2, type="html", align=TRUE, no.space=TRUE, omit.stat="ser", intercept.bottom = FALSE, single.row = TRUE, out="values.html")


#Robustness tests. 

#The following regression models produce the results in table S2. The stargazer command produces the table with all the results. 
reg1d <- lm(Du_Pont_Ambition~ GDP_ppp_2015_log+ Democracy_index +coal_rents_2015+natural_gas_rents_2015+oil_rents_2015, data = mydata)
reg1e <- lm(Du_Pont_Ambition~ GDP_ppp_2015_log+ Democracy_index, data = mydata)
reg1f <- lm(Du_Pont_Ambition~ GDP_ppp_2015_log+ Democracy_index +coal_rents_2015, data = mydata)
reg1g <- lm(Du_Pont_Ambition~ GDP_ppp_2015_log+ Democracy_index +vulnerability_2015, data = mydata)
reg1h <- lm(Du_Pont_Ambition~ GDP_ppp_2015_log+ Democracy_index +coal_rents_2015+ vulnerability_2015, data = mydata)
reg1i <- lm(Du_Pont_Ambition~ Democracy_index +coal_rents_2015+ vulnerability_2015, data = mydata)
reg1j <- lm(Du_Pont_Ambition~ GDP_ppp_2015_log +coal_rents_2015+ vulnerability_2015, data = mydata)
stargazer(reg1d, reg1e, reg1f, reg1g, reg1h, reg1i, reg1j, type="html", align=TRUE, no.space=TRUE, omit.stat="ser", intercept.bottom = FALSE, single.row = TRUE, out="material-factors-robustness.html")

##The following regression models produce the results in table S3. The stargazer command produces the table with all the results. 
reg20 <- lm(CCPI_2019~ GDP_ppp_2015_log+ Democracy_index +coal_rents_2015+natural_gas_rents_2015+oil_rents_2015+vulnerability_2015, data = mydata)
reg22 <- lm(CAT_ranking~ GDP_ppp_2015_log+ Democracy_index +coal_rents_2015+natural_gas_rents_2015+oil_rents_2015+vulnerability_2015, data = mydata)
stargazer(reg20, reg22, type="html", align=TRUE, no.space=TRUE, omit.stat="ser", intercept.bottom = FALSE, single.row = TRUE, out="CCPI-CAT-Material-factors-NDC-ambition.html")

#The following regression models produce the results in table S4. The stargazer command produces the table with all the results. 
reg3c <- Du_Pont_Ambition <- lm (Du_Pont_Ambition~support_Paris_agreement+ GDP_ppp_2015_log+ Democracy_index +coal_rents_2015+natural_gas_rents_2015+oil_rents_2015, data = mydata)
reg3d <- Du_Pont_Ambition <- lm (Du_Pont_Ambition~support_Paris_agreement+ GDP_ppp_2015_log+ Democracy_index, data = mydata)
reg3e <- Du_Pont_Ambition <- lm (Du_Pont_Ambition~support_Paris_agreement+ GDP_ppp_2015_log, data = mydata)
reg3f <- Du_Pont_Ambition <- lm (Du_Pont_Ambition~support_Paris_agreement+ Democracy_index +coal_rents_2015+natural_gas_rents_2015+oil_rents_2015 + vulnerability_2015, data = mydata)
reg3g <- Du_Pont_Ambition <- lm (Du_Pont_Ambition~support_Paris_agreement+ Democracy_index +coal_rents_2015+natural_gas_rents_2015+oil_rents_2015, data = mydata)
reg3h <- Du_Pont_Ambition <- lm (Du_Pont_Ambition~support_Paris_agreement+ Democracy_index, data = mydata)
stargazer(reg3c, reg3d, reg3e, reg3f, reg3g, reg3h, type="html", align=TRUE, no.space=TRUE, omit.stat="ser", intercept.bottom = FALSE, single.row = TRUE, out="PA-support-robustness.html")

#The following regression models produce the results in table S5. The stargazer command produces the table with all the results. 
reg4a <- lm (Du_Pont_Ambition~ postmaterialism+cosmopolitanism + religion+political_orientation, data = mydata)
reg4b <- lm (Du_Pont_Ambition~ postmaterialism+cosmopolitanism + religion+political_orientation+ GDP_ppp_2015_log+Democracy_index , data = mydata)
reg4c <- lm (Du_Pont_Ambition~ postmaterialism+cosmopolitanism + religion+political_orientation+ GDP_ppp_2015_log+Democracy_index +coal_rents_2015+natural_gas_rents_2015+oil_rents_2015+ vulnerability_2015, data = mydata)
stargazer(reg4a,reg4b, reg4c, type="html", align=TRUE, no.space=TRUE, omit.stat="ser", intercept.bottom = FALSE, single.row = TRUE, out="values-robustness.html")

#The following regression models produce the results in table S6. The stargazer command produces the table with all the results. We first invert the index to facilitate interpretation.
mydata$cosmopolitanism_index <- abs(mydata$cosmopolitanism_index - max(mydata$cosmopolitanism_index, na.rm = TRUE))
reg6a <- lm (Du_Pont_Ambition~ postmaterialism+cosmopolitanism_index, data = mydata)
reg6b <- lm (Du_Pont_Ambition~ postmaterialism+cosmopolitanism_index+ GDP_ppp_2015_log+ Democracy_index +coal_rents_2015+natural_gas_rents_2015+oil_rents_2015+ vulnerability_2015, data = mydata)
stargazer(reg6a, reg6b, type="html", align=TRUE, no.space=TRUE, omit.stat="ser", intercept.bottom = FALSE, single.row = TRUE, out="cosmopolitanism_index-NDC-ambition.html")

#The following regression models produce the results in table S7. The stargazer command produces the table with all the results. 
reg1_uncond<- lm(Du_Pont_Ambition~ GDP_ppp_2015_log+ Democracy_index +coal_rents_2015+natural_gas_rents_2015+oil_rents_2015+vulnerability_2015, data=subset(mydata, NDC_unconditional=="1"))
reg2_uncond <- lm (Du_Pont_Ambition~GDP_ppp_2015_log+ Democracy_index +coal_rents_2015+ oil_rents_2015 + natural_gas_rents_2015 + vulnerability_2015+support_Paris_agreement, data=subset(mydata, NDC_unconditional=="1"))
reg3_uncond <- lm (Du_Pont_Ambition~GDP_ppp_2015_log+ Democracy_index +coal_rents_2015+ oil_rents_2015 + natural_gas_rents_2015 + vulnerability_2015+postmaterialism+local_global, data=subset(mydata, NDC_unconditional=="1"))
stargazer(reg1_uncond, reg2_uncond, reg3_uncond, type="html", align=TRUE, no.space=TRUE, omit.stat="ser", intercept.bottom = FALSE, single.row = TRUE, out="uncond-robustness-test-NDC-ambition.html")




